import request from '@/modules/index/utils/request';
import qs from "qs";
import { downloadFile } from '@/utils/common';


const store = {
    state:{
        detectListRowData:{},
        algoFileListRowData:{},
        currentDetectLeftRowId:'', // 故障诊断-左列表点击当前行的id
        currentPreviewLeftRowId:'', // 故障预测-左列表点击当前行的id
    },
    mutations:{
        SET_DETECTLISTROWDATA: (state, data) => {
            state.detectListRowData = data
        },
        SET_ALGOFILELISTROWDATA: (state, data) => {
            state.algoFileListRowData = data
        },
        SET_CURRENTDETECTLEFTROWID: (state, data) => {
            state.currentDetectLeftRowId = data
        },
        SET_CURRENTPREVIEWLEFTROWID: (state, data) => {
            state.currentPreviewLeftRowId = data
        },
    },
    actions: {
        // 基于源码诊断列表-查询
        async detectList(context,params) {
            const data = await request({
                // url: '/algoTemplateFile/list',
                url: params ? `/algoTemplateFile/list?${params}` : '/algoTemplateFile/list',
                method: 'get'
            });
            return data;
        },
        // 基于源码诊断列表-分页查询
        async detectPageList(context,params) {
            const data = await request({
                // url: '/algoTemplateFile/list',
                url: params ? `/algoTemplateFile/pageList?${params}` : '/algoTemplateFile/list',
                method: 'get'
            });
            return data;
        },
        // 基于源码诊断列表-删除
        async detectBatchDelete(context, params) {
            const data = await request({
                url: '/algoTemplateFile/deleteByIds',
                method: 'post',
                params:params,
                paramsSerializer: (params) => {
                    return qs.stringify(params, { indices: false });
                },
            });
            return data;
        },
        // 算法文件列表-分页查询
        async algoFileList(context,params) {
            const data = await request({
                // url: '/algoTemplateFile/list',
                url: params ? `/algoVersionFile/pageList?${params}` : '/algoVersionFile/pageList',
                method: 'get'
            });
            return data;
        },
        // 算法文件列表-删除
        async algoFileBatchDelete(context, params) {
            const data = await request({
                url: '/algoVersionFile/deleteByIds',
                method: 'post',
                params:params,
                paramsSerializer: (params) => {
                    return qs.stringify(params, { indices: false });
                },
            });
            return data;
        },
        // 算法文件列表-下载
        async algoFileBatchDownload(context, params) {
            const data = await request({
                url: '/algoVersionFile/download',
                method: 'post',
                params:params,
                paramsSerializer: (params) => {
                    return qs.stringify(params, { indices: false });
                },
                responseType: 'blob'
            });
            downloadFile(data);
            return data;
        },
        // 算法裁剪弹框中确定请求
        async algoCutConfirm(context, params) {
            const data = await request({
                url: `/algoTemplateCondition/batchOptBfClearCondition?algoTemplateId=${params.algoTemplateId}&algoTemplateVersionId=${params.algoTemplateVersionId}&type=${params.type}`,
                method: 'post',
                data:params.t,
            });
            return data;
        },
    }
};

export default store;
